package com.mgg.common.aspect;

import com.mgg.common.exception.DAOException;
import com.mgg.common.exception.ServiceException;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @Author: lijun
 * @Date: 2018/9/11 14:23
 */
@Aspect
@Component
public class ServiceAspect {

    protected Logger logger = LoggerFactory.getLogger(getClass());

    @Pointcut("execution(* com.mgg..*.service..*.*(..))")
    public void pointcut(){}

    @Around("pointcut()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable{
        try {
            Object object = pjp.proceed();
            return object;
        } catch (DAOException e) {
            logger.error(e.getMessage(),e);
            throw new ServiceException("007","数据查询失败");
        }
    }
}